package cn.com.eado.crm.m.net;

import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.RequestBody;

/**
 * Created by Administrator on 2018/3/16.
 */

public class Okhttp3Utils {

    public static <T> RequestBody getRequestBody(T t, String field){
        String data = new Gson().toJson(t);  //转json字符串
//        Log.e("tag","data = "+data);
        return Okhttp3Utils.getJsonRequestBody(field, data);  //body 所属的字段:data
    }

    private static RequestBody getJsonRequestBody(String paramName, String jsonData){
        HashMap<String,String> paramsMap=new HashMap<>();
        paramsMap.put(paramName, jsonData);  //一定要
        String strEntity = new Gson().toJson(paramsMap);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"),strEntity);

        return body;
    }

}
